<template>
	<view>
		<cu-custom bgColor="bg-white" :isBack="true">		<block slot="backText"></block>
			<block slot="content">{{title}}</block>
		</cu-custom>
		
		<view class="whole-box">
		<!-- <view class="whole-box" style="background-color: #FB7483;"> -->
			<view class="gold-black-box">
				
				<view class="top-box">
					<view class="top-box-content">
						
						<view class="data-box">
							<view>参与金额:<text>{{total?total:'0'}}</text></view>
							
						</view>
						<view class="data-box2">
							<view>本金待发放:<text>{{total_pay?total_pay:'0.00'}}</text></view>
						</view>
						<view class="data-box2">
							<view>本金已发放:<text>{{total_ypay?total_ypay:'0.00'}}</text></view>
						</view>
						<view class="data-box2">
							<view>预期代销收益:<text>{{team_order?team_order:'0'}}</text></view>
						</view>
						<view class="data-box2">
							<view>累计结算收益:<text>{{team_yorder?team_yorder:'0'}}</text></view>
						</view>
					</view>
					
				</view>
				
				<view class="my-data-box" :style="'height:'+scroll_box_height+'px'" >
					
					<view class="my-data-box-content" >
						<scroll-view scroll-y :style="'height:'+scrollHeight+'px'" @scrolltolower="getMore">
						<block v-for="(item,index) in list" :key="index" >
							<view class=" padding margin-top order-item">
								<view class="solid-bottom space-between padding-bottom-sm">
									<view class="text-orange" style="color: #000000;">
										<text>{{item.sellprodunt.title}}</text>
									</view>
									
								</view>
								<view class="space-between padding-tb-sm solid-bottom" >
									<view class="thumb bg-grey">
										<image :src="item.sellprodunt.picture" mode="aspectFill"></image>
									</view>
									<view class="w100 margin-left-sm overflow">
										<view class="product-name w100">
											<!-- <view class="text-black text-df text-overflow-2 w100"></view>
											<view class="cu-tag sm margin-top-xs" ></view> -->
										</view>
										<!-- <view class="margin-tb-xs">
											<text class="cu-tag bg-brown light sm" ></text>
										</view> -->
										<view class="space-between">
											<text class="text-price text-lg text-red">{{item.sellprodunt.wholesale_price}}</text>
											<text class="text-black">x{{item.num}}</text>
										</view>
									</view>
								</view>
								<view class="text-right padding-tb-sm solid-bottom text-black">
									共<text class="text-red">{{item.num}}</text>件商品 实付款<text class="text-price text-red margin-left-xs">{{item.pay_money}}</text>
								</view>
								<view class=" margin-top-sm" >
									
									<view  class=" round margin-left-sm line-gray" style="width: 70%;" >
										<view>代销状态:{{item.jd_status}}</view>
										<text><cmd-progress :percent="item.jd_num" stroke-color="#fe2772"></cmd-progress></text>
									</view>
									<view class="text-right" style="margin-top:-40rpx" >
										<view style="color: #1A181E;border: 1px solid #1A181E;" class="cu-btn round margin-left-sm line-gray" @tap="goPage('/pages/member/wait_integral/list?orderid='+item.id )">
											
											<text>查看详情</text>
										</view>
									</view>
								</view>
							</view>
						</block>
						</scroll-view>
						
					</view>
				</view>	
				
			</view>
		</view>		
		
	
		<Navbar ref="navbar" PageCur="order"></Navbar>
	</view>
</template>

<script>
	import cmdProgress from "@/components/cmd-progress/cmd-progress.vue"
	import Navbar from '@/components/default/Navbar.vue'
	// import Foot from '@/components/default/foot.vue'
	import {
		mapState
	} from 'vuex'
	export default {
		// name: "order",
		components: {
			cmdProgress,
			Navbar
		},
		computed: mapState(['forcedLogin', 'hasLogin', 'channelLogin']),
		mounted() {
			// this.getScrollH()
		},
		data() {
			return {
				theme: this.$config.THEME(),
				list: null,
				is_channel: 0,
				title: '代销详情',
				member: [],
				total: 0,
				total_pay: 0.00,
				team_order:0,
				total_ypay: 0.00,
				team_yorder:0,
				team_pay_money:0.00,
				scroll_box_height: 900,
				scrollHeight: 900,
				hasMore:true,
				loading:false,
				page:1,
			};
		},
		onLoad(options) {
			
			if (this.$common.loginAuth(true)) {
				this.$common.getMember().then((member)=>{
					this.member = member
					
				})
				this.$nextTick(function() {
					this.getShowdata();
					uni.startPullDownRefresh({})
					// this.getScrollH()
					
				})
			}
		},
		onShow() {
			if (this.$common.loginAuth(true)) {
				if (this.$common.getCache('order_reload')) {
					this.$common.rmCache('order_reload')
					this.$nextTick(function() {
						uni.startPullDownRefresh({})
					})
				}
			}
		},
		methods: {
			getScrollH() {
				let sys = uni.getSystemInfoSync();
				let winHeight = sys.screenHeight;
				//console.log(winHeight)
				let _this = this
				// 计算scroll-view高度
				let query = uni.createSelectorQuery().in(_this);
				query.select('.top-box').boundingClientRect()
				query.select('.scroll-list').boundingClientRect()
				// query.select('.foot').boundingClientRect()
				query.selectViewport()
				query.exec(function(res) {
					console.log(winHeight)
					console.log(res[0].bottom)
					_this.scroll_box_height = winHeight - res[0].bottom - 12 - 24
					console.log(_this.scroll_box_height)
					_this.scrollHeight = winHeight - res[1].bottom - 24
					
				})
			},
			
			getList(index) {
				
				if (!this.hasMore || this.loading) return

				this.loading = true
				let params = {
					page: this.page,
				}
				
				this.$http
					.get('sell_order_index', params)
					.then((response) => {
						console.log(response)
						let list = this.list
						if (response.data.data.length > 0) {
							list = list.concat(response.data.data)
							
						} else {
							this.hasMore = false
							
						}
						this.list = list
						this.loading = false
						this.page++
						uni.stopPullDownRefresh()
					})
					.catch((response) => {
						console.log(response)
					})
			},
			getShowdata(){
			
				this.$http
					.get('sell_order_total', {})
					.then((response) => {
						console.log(response)
						this.total = response.data.data.total
						this.total_pay = response.data.data.total_pay
						this.team_order = response.data.data.team_order
						this.total_ypay = response.data.data.total_ypay
						this.team_yorder = response.data.data.team_yorder
						uni.stopPullDownRefresh()
					})
					.catch((response) => {
						console.log(response)
					})
			},
			reloadList() {
				uni.startPullDownRefresh({})
			},
			getMore() {
				this.getList()
			},
		},
		onPullDownRefresh() {
			
			this.list = []
			this.hasMore = true
			this.page = 1
			this.loading = false
			this.getList()
			
		},
		onReachBottom() {
			this.getList()
		},
	}
</script>

<style>
	.thumb {
		width: 160rpx;
		height: 160rpx;
		min-width: 160rpx;
		border-radius: 10rpx;
		overflow: hidden;
	}

	.thumb image {
		width: 100%;
		height: 100%;
		
	}

	.product-name {
		/* height: 80rpx; */
		line-height: 40rpx;
		overflow: hidden;
	}
</style>
<style>
	.cu-active{
		/* background: -webkit-linear-gradient(left, #FFEA5E, #FFEA5E, #FCC710, #FCC710); */
		/* background-color: #815ad7; */
		background-color: rgb(254,39,114);
		color: #ffffff;
		border-radius: 20px;
	}
	.nav .cu-item{
		height: 25px!important;
		line-height: 25px!important;
		text-align: center;
		/* float: left; */
		/* width: 12%; */
	}
	.whole-box{
		/* background-color: #333333; */
		min-height: calc(100vh - 45px);
		padding: 12px 0;
		background-image: url(../../../static/red-new/new-back.png);
		background-size: 100% 100%;
	}
	.gold-black-box{
		padding: 12px 0;
		margin: 0 10rpx;
		/* border: 2rpx solid #999999; */
		border-radius: 30rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
	}
	
	.gold-black-box .top-box{
		/* margin-top: 25rpx; */
		width: 690rpx;
		height: 360rpx;
		/* border: 2rpx solid #999999; */
		border-radius: 15rpx;
		overflow: hidden;
		position: relative;
		background-color: #ffffff;
	}
	.top-box .top-box-bg{
		width: 100%;
		height: 100%;
	}
	.top-box .top-box-content{
		width: 690rpx;
		/* height: 276rpx; */
		position: absolute;
		left: 0;
		top: 0;
		display: flex;
		flex-direction: column;
		align-items: center;
	}
	.top-box-content .avatar{
		margin-top: 26rpx;
		width: 150rpx;
		height: 150rpx;
		border-radius: 50%;
		border: 1rpx solid #EAEAEA;
	}
	.top-box-content .username{
		margin-top: 14rpx;
		font-size: 28rpx;
		font-weight: bold;
		color: #000000;
	}
	.top-box-content .bg-logo{
		width: 196rpx;
		height: 54rpx;
		padding-left: 20rpx;
	}
	.top-box-content .page-title{
		padding-left: 40rpx;
		font-size: 36rpx;
		font-weight: bold;
		color: #000000;
	}
	
	.top-box-content .data-box{
		padding: 0 40rpx;
		width: 100%;
		display: flex;
		/* justify-content: space-around; */
/* 		align-items: center;
		text-align: center; */
		margin-top: 12px;
	}
	.data-box view{
		width: 50%;
		font-size: 28rpx;
		font-weight: bold;
		color: #000000;
	}
	.data-box view text{
		margin-left: 10rpx;
	}
	.top-box-content .data-box2{
		padding: 0 40rpx;
		width: 100%;
		display: flex;
		/* justify-content: space-around;
		align-items: center;
		text-align: center; */
		margin: 8px 0px;
	}
	.data-box2 view{
		width: 50%;
		font-size: 28rpx;
		font-weight: bold;
		color: #000000;
	}
	.data-box2 view text{
		margin-left: 10rpx;
	}
	
	.top-box .level-detail{
		position: absolute;
		top: 52rpx;
		left: 400rpx;
		padding: 0 20rpx;
		height: 40rpx;
		line-height: 40rpx;
		border-radius: 20rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		/* background-color: #000000; */
		/* background: -webkit-linear-gradient(left, #C48415, #C48415, #EDCB3E, #CA8B0F); */
		/* background: -webkit-gradient(linear, 0 0, 0 100%, from(#C48415), to(#CA8B0F)); */
	}
	.level-detail image{
		width: 145rpx;
		height: 43rpx;
		margin-right: 6rpx;
		flex-shrink: 0;
		left: -13px;
		/* top: 16px; */
	}
	.level-detail text{
		font-size: 22rpx;
		font-weight: bold;
		color: #ffffff;
		position: absolute;
		margin-top: 10rpx;
		margin-left: -15rpx;
	}
	
	
</style>

<style>
	.gold-black-box .my-data-box{
		margin-top: 12px;
		width: 764rpx;
		height: 336rpx;
		/* border: 2rpx solid #999999; */
		border-radius: 30rpx;
		overflow: hidden;
		position: relative;
	}
	.my-data-box .my-data-box-bg{
		width: 100%;
		height: 100%;
	}
	.my-data-box .my-data-box-content{
		width: 100%;
		/* height: 336rpx; */
		position: absolute;
		left: 0;
		top: 0;
		/* display: flex;
		justify-content: space-between;
		align-items: center; */
		padding: 0 40rpx;
	}
	
	.my-data-box-content .scroll-list{
		
	}
	.scroll-list .my-status{
		color: #E5D4B9
	}
	
	.my-data-box-content .order-box{
		
	}
	.order-box{
		
	}
</style>
<style>
	.order-item{
		/* border: 1rpx solid #999999; */
		border-radius: 20rpx;
		margin-top: 20rpx;
		width: 690rpx;
		height: 500rpx;
		overflow: hidden;
		position: relative;
		background: #ffffff;
	}
	/* .order-item .my-data-box-bg{
		width: 100%;
		height: 100%;
	}
	
	.order-item .my-data-box-content{
		width: 610rpx;
		height: 480rpx;
		position: absolute;
		left: 0;
		top: 0;
		padding: 20rpx;
	} */
</style>